<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <body>

        <ui:composition template="/template.xhtml">

            <ui:define name="content">
                <h:form id="fprincipal">
                    <p:messages/>
                    <p:panel
                        id="pprincipal"
                        header="Formulacao">
                        <h:panelGrid 
                            id="pgprincipal"
                            columns="2">  
                            <h:outputLabel
                                id="olnome"
                                for="itnome" 
                                value="Nome da Aplicação: "/>
                            <p:inputText 
                                id="itnome" 
                                value="#{aplicacaoBean.aplicacao.nome}"
                                readonly="true"/>
                        </h:panelGrid>  
                    </p:panel>
                    <p:panel header="Tabela de Nutrientes">
                        <p:dataTable 
                            id="dtformulacao"
                            value="#{aplicacaoBean.aplicacao.formulacaoList}" 
                            var="formulacao">
                            <p:column>
                                <f:facet name="header">  
                                    <h:outputText value="Nutriente" />  
                                </f:facet>  
                                <h:outputLabel value="#{formulacao.nutriente.nome}"/>
                            </p:column>
                            <p:column headerText="Quantidade" >  
                                <p:column>
                                    <f:facet name="header">  
                                        <h:outputText value="Quantidade" />  
                                    </f:facet>  
                                    <h:outputLabel value="#{formulacao.quantidade}"/>
                                </p:column>
                            </p:column>
                            <p:column>
                                <f:facet name="header">  
                                    <h:outputText value="Opções"/>  
                                </f:facet>  
                                <p:commandButton            
                                    ajax="false" 
                                    action="#{aplicacaoBean.alterarQtd}" 
                                    value="Alterar">
                                    <f:setPropertyActionListener 
                                        target="#{formulacaoBean.formulacao}" 
                                        value="#{formulacao}"/>
                                </p:commandButton>
                            </p:column>  

                        </p:dataTable>
                        <p:commandButton 
                            ajax="false" 
                            action="#{aplicacaoBean.salvar}" 
                            value="Salvar">
                            <f:setPropertyActionListener 
                                target="#{aplicacaoBean.aplicacao}" 
                                value="#{aplicacao}"/>
                        </p:commandButton>
                    </p:panel>
                </h:form>
            </ui:define>
        </ui:composition>
    </body>
</html>
